/**
 * @将一个正整数转化为基数
 *
 * @author	 wangshikun <wangshikun2010@gmail.com>
 * @copyright	(c) 2012 wangshikun <wangshikun2010@gmail.com>
 * @license	http://www.opensource.org/licenses/mit-license.php The MIT License
 * @package	default
 * @subpackage	default
 */

#include <stdio.h>
#include <cs50.h>
#include <stdlib.h>

int main(int argc, char *argv[]) {
	const char charset[16] = {'0','1','2','3','4','5','6','7','8','9','A','B','C','D','E','F'};
	int number[64];
	long int num;
	int next, base, index=0;

	printf("请输入一个数：");
	scanf("%ld", &num);

	do {
		printf("除数：");
		scanf("%d", &base);
	} while (base<2 || base>16);

	do {
		number[index] = num % base;
		index++;
		num = num / base;
	} while (num != 0);

	printf("结果为：");

	for (--index; index>=0; --index) {
		next = number[index];
		printf("%c", charset[next]);
	}

	printf("\n");

	return 0;
}
